import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:kq_flutter_core_widget/widgets/button/kq_ink_well.dart';

import '../../config/kq_global.dart';
import '../../resources/images.dart';

/// 右下角悬浮按钮
class KqFloatingButton extends StatelessWidget {
  /// 按钮类型，详见[FloatingButtonType]
  final FloatingButtonType buttonType;

  /// 是否有权限
  final bool disable;

  /// 点击回调
  final Function(bool disabled) onTap;

  const KqFloatingButton(
      {Key? key,
      required this.buttonType,
      required this.onTap,
      this.disable = false})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    String img = disable ? Images.commonIcAdd64Disabled : Images.commonIcAdd64;
    if (buttonType == FloatingButtonType.add) {
      img = disable ? Images.commonIcAdd64Disabled : Images.commonIcAdd64;
    } else if (buttonType == FloatingButtonType.close) {
      img = disable ? Images.commonIcClose64Disabled : Images.commonIcClose64;
    } else if (buttonType == FloatingButtonType.changeTask) {
      img = disable
          ? Images.commonIcCutorder64Disabled
          : Images.commonIcCutorder64;
    } else if (buttonType == FloatingButtonType.upload) {
      img = disable ? Images.commonIcUpload64Disabled : Images.commonIcUpload64Enabled;
    }
    return KqInkWell(
        onTap: () {
          onTap(disable);
        },
        enableRipple: false,
        child: Image.asset(img,
            width: 64.r,
            height: 64.r,
            fit: BoxFit.fill,
            package: KqGlobal.packageName));
  }
}

enum FloatingButtonType {
  /// 新增
  add,

  /// 关闭
  close,

  /// 切单
  changeTask,

  /// 上传
  upload
}
